<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../../js/vue.js"></script>
</head>
<body>
    <div id="app">
        <div v-test></div>
        <div v-test="{bg:'pink'}"></div>
    </div>
    <script>
        Vue.directive("test",(el,binding)=>{
            el.style.cssText="width:200px;height:200px;background:red;position:absolute";
            el.style.background=binding.value?binding.value.bg:"red";
            el.onmousedown=function(e){
                disX=e.clientX-el.offsetLeft;
                disY=e.clientY-el.offsetTop;

                document.onmousemove=function(e){
                    el.style.left=e.clientX-disX+"px";
                    el.style.top=e.clientY-disY+"px";     
                }
               
            }
            document.onmouseup=function(){
                        document.onmousemove=null;
                    }
        })
        new Vue({
            el:"#app",
           
        })
    
    </script>
</body>
</html>